<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:c="http://java.sun.com/jsp/jstl/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	template="/WEB-INF/layout/t.xhtml">

	<ui:define name="title">
		<h:outputText value="Amministrazione del portale" />
	</ui:define>
	<ui:define name="content">
		<script type="text/javascript"
			src="#{request.contextPath}/js/it_editor.js"></script>
		<script type="text/javascript">
         //<![CDATA[
function addImageBrowser() {
            myEditor.on('toolbarLoaded', function() {
    //When the toolbar is loaded, add a listener to the insertimage button
    this.toolbar.on('insertimageClick', function() {
        //Get the selected element
        var _sel = this._getSelectedElement();
        //If the selected element is an image, do the normal thing so they can manipulate the image
        if (_sel && _sel.tagName && (_sel.tagName.toLowerCase() == 'img')) {
            //Do the normal thing here..
        } else {
            //They don't have a selected image, open the image browser window
            win = window.open('#{request.contextPath}/private/gallerie/images.jsf', 'IMAGE_BROWSER',
                'left=20,top=20,width=500,height=500,toolbar=0,resizable=0,status=0');
            if (!win) {
                //Catch the popup blocker
                alert('Please disable your popup blocker!!');
            }
            //This is important.. Return false here to not fire the rest of the listeners
            return false;
        }
    }, this, true);
}, myEditor, true);

         }

          window.onload = addImageBrowser;
         //]]>
      </script>
		<h:form prependId="false">

			<p:messages id="messages" />
			<center>
				<p:panel header="Gestione Galleria di Foto">

					<h:panelGrid columns="2" style="width: 95%">

						<h:outputLabel for="titolo" value="Titolo(*)" />
						<h:inputText id="titolo"
							value="#{gallerieController.element.titolo}" required="true"
							style="width: 100%;" />


						<h:outputLabel for="descrizione" value="Descrizione:" />
						<p:editor id="descrizione"
							value="#{gallerieController.element.descrizione}" width="640px"
							height="320px" widgetVar="myEditor" language="it" />

					</h:panelGrid>
					<br />
				</p:panel>
				<br /> <br />

				<h:panelGrid columns="4">
					<h:commandButton action="#{gallerieController.save}"
						value="salva galleria" immediate="false"
						rendered="#{not gallerieController.editMode}" />

					<h:commandButton action="#{gallerieController.update}"
						value="aggiorna galleria" immediate="false"
						rendered="#{gallerieController.editMode}" />

					<h:commandButton action="#{gallerieController.delete}"
						value="elimina galleria" rendered="#{gallerieController.editMode}"
						immediate="true"
						onclick="if (!confirm('Vuoi davvero eliminare?')) return false" />
				</h:panelGrid>
			</center>
		</h:form>

	</ui:define>
</ui:composition>